package cn.bandeqing.productType.controller;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.productType.req.ProductTypeSaveOrUpdateReq;
import cn.bandeqing.productType.req.ProductTypeTableReq;
import cn.bandeqing.productType.resp.ProductTypeTable;
import cn.bandeqing.productType.rpc.IProductTypeRpc;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/productType")
@RestController
@Tag(name = "产品类目")
public class ProductTypeController {

    @DubboReference
    private IProductTypeRpc productTypeRpc;

    @Operation(summary = "表格")
    @PostMapping("/table")
    public Resp<Table<ProductTypeTable>> table(@RequestBody @Valid ProductTypeTableReq req) {
        return productTypeRpc.table(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/saveOrUpdate")
    public Resp<Void> saveOrUpdate(@RequestBody @Valid ProductTypeSaveOrUpdateReq req) {
        productTypeRpc.saveOrUpdate(req);
        return Resp.success();
    }

}
